Only read one package from registry tarballs
authorAlex Crichton <alex@alexcrichton.com>
Wed, 11 Nov 2015 02:17:23 +0000 (18:17 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 11 Nov 2015 02:17:23 +0000 (18:17 -0800)
Even if multiple ones are included, don't recurse!

Closes #2132

src/cargo/sources/path.rs
tests/test_cargo_registry.rs

index eedb88303bf107440c50ad99abb6727dd911a1ea..fabdc27ae49ae710bf4ed82b2cce6c5a72108219 100644 (file)
@@ -59,12 +59,19 @@ impl<'cfg> PathSource<'cfg> {
     pub fn read_packages(&self) -> CargoResult<Vec<Package>> {
         if self.updated {
             Ok(self.packages.clone())
-        } else if self.id.is_path() && self.id.precise().is_some() {
+        } else if (self.id.is_path() && self.id.precise().is_some()) ||
+                  self.id.is_registry() {
             // If our source id is a path and it's listed with a precise
             // version, then it means that we're not allowed to have nested
-            // dependencies (they've been rewritten to crates.io dependencies)
-            // In this case we specifically read just one package, not a list of
-            // packages.
+            // dependencies (they've been rewritten to crates.io dependencies).
+            //
+            // If our source id is a registry dependency then crates are
+            // published one at a time so we don't recurse as well. Note that
+            // cargo by default doesn't package up nested dependencies but it
+            // may do so for custom-crafted tarballs.
+            //
+            // In these cases we specifically read just one package, not a list
+            // of packages.
             let path = self.path.join("Cargo.toml");
             let (pkg, _) = try!(ops::read_package(&path, &self.id,
                                                   self.config));
index 3f9fd85115a289c7140037b78418f1dd5967c60f..23be64c55869108ca01961da8dc8578490805a6b 100644 (file)
@@ -896,3 +896,43 @@ test!(update_multiple_packages {
                        .with_stdout_contains(format!("\
 {compiling} foo v0.5.0 ([..])", compiling = COMPILING)));
 });
+
+test!(bundled_crate_in_registry {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.5.0"
+            authors = []
+
+            [dependencies]
+            bar = "0.1"
+            baz = "0.1"
+        "#)
+        .file("src/main.rs", "fn main() {}");
+    p.build();
+
+    Package::new("bar", "0.1.0").publish();
+    Package::new("baz", "0.1.0")
+        .dep("bar", "0.1.0")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "baz"
+            version = "0.1.0"
+            authors = []
+
+            [dependencies]
+            bar = { path = "bar", version = "0.1.0" }
+        "#)
+        .file("src/lib.rs", "")
+        .file("bar/Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.1.0"
+            authors = []
+        "#)
+        .file("bar/src/lib.rs", "")
+        .publish();
+
+    assert_that(p.cargo("run"), execs().with_status(0));
+});